﻿namespace BorgExt
{
    public enum LogType
    {
        Info,
        Warning,
        Error
    }

    public class Logger : RuntimeElement
    {
        public event LogEventHandler Log;

        protected internal Logger()
        { }

        internal void OnLog(object sender, string msg, params object[] args)
        {
            OnLog(VerbosityLevel.Normal, LogType.Info, sender, msg, args);
        }

        internal void OnLog(LogType type, object sender, string msg, params object[] args)
        {
            OnLog(VerbosityLevel.Normal, type, sender, msg, args);
        }

        internal void OnLog(VerbosityLevel verbosityLevel, object sender, string msg, params object[] args)
        {
            OnLog(verbosityLevel, LogType.Info, sender, msg, args);
        }

        internal void OnLog(VerbosityLevel verbosityLevel, LogType type, object sender, string msg, params object[] args)
        {
            OnLog(verbosityLevel, sender, new LogEventArgs(type, string.Format(msg, args)));
        }

        internal void OnLog(VerbosityLevel verbosityLevel, object sender, LogEventArgs args)
        {
            if (Runtime.VerbosityLevel < verbosityLevel || Log == null)
                return;
            
            Log(sender, args);
        }
    }
}

